package com.google.coffeeshop.dao.impl;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

import com.google.coffeeshop.dao.ReceiptNoteDAO;
import com.google.coffeeshop.entity.ReceiptNoteDTO;
import com.googlecode.genericdao.search.Search;


public class ReceiptNoteDAOImpl extends AbstractBaseDAOImpl<ReceiptNoteDTO, Long> implements ReceiptNoteDAO {

	public List<ReceiptNoteDTO> findBetweenDates(Date beginDate, Date endDate){
		Search search = new Search(ReceiptNoteDTO.class);
		search.setFirstResult(0);
		search.setMaxResults(Integer.MAX_VALUE);
		search.addFilterGreaterOrEqual("receiptDate", beginDate);
		
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(endDate);
		calendar.set(Calendar.HOUR_OF_DAY, 23);
		calendar.set(Calendar.MINUTE, 59);
		calendar.set(Calendar.SECOND, 59);
		search.addFilterLessOrEqual("receiptDate", calendar.getTime());
		
		List<ReceiptNoteDTO> receiptNotes = this.search(search);
		if (null == receiptNotes || receiptNotes.isEmpty()) {
			return null;
		}
		return receiptNotes;
	}

	@Override
	public List<ReceiptNoteDTO> findByDate(Date date) {
		// TODO Auto-generated method stub
		
		Search search = new Search(ReceiptNoteDTO.class);
		search.setFirstResult(0);
		search.setMaxResults(Integer.MAX_VALUE);
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		calendar.set(Calendar.HOUR_OF_DAY, 23);
		calendar.set(Calendar.MINUTE, 59);
		calendar.set(Calendar.SECOND, 59);
		search.addFilterLessOrEqual("receiptDate", calendar.getTime());
		
		List<ReceiptNoteDTO> receiptNotes = this.search(search);
		if (null == receiptNotes || receiptNotes.isEmpty()) {
			return null;
		}
		return receiptNotes;
	}
	
}
